/**
 * Splash
 * 
 * 03/11/2013
 * 
 * Copyright GPL
 */
package com.jtmproject.activities;

import com.jtmproject.classes.GetPreferences;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
 * This class is an activity that shows splash animation
 * @author Javier Tejedor
 */
public class Splash extends Activity implements OnClickListener, 
AnimationListener {

	
	/* (non-Javadoc)
	 * @see android.app.Activity#onCreate(android.os.Bundle)
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_splash);
				
		if(GetPreferences.getGetPreferences().isEnableSplash(this)) {
			//the user wants to show the splash activity
			setTitleSettings();
			setLogoSettings();
			setContainerSettings();
			
		}else{
			
			goMainActivity();
			
		}
		
	}
	
	/**
	 * this adds a listener into the main container for catching the touches 
	 * screen by the user
	 */
	private void setContainerSettings() {
		RelativeLayout container = 
				(RelativeLayout) findViewById(R.id.container);
        container.setOnClickListener(this);
	}
	
	/**
	 * this adds an animation into the textview
	 */
	private void setTitleSettings() {
		TextView title = (TextView) findViewById(R.id.text_splash);
		title.startAnimation(AnimationUtils.loadAnimation(this, 
				R.anim.anim_text));
	}
	
	/**
	 * this adds an animation into the logo
	 */
	private void setLogoSettings(){
		ImageView logo = (ImageView) findViewById(R.id.image_splash);
		Animation imageAnimation = AnimationUtils.loadAnimation(this, 
				R.anim.anim_image);
        logo.startAnimation(imageAnimation);
        imageAnimation.setAnimationListener(this);
	}

	/* (non-Javadoc)
	 * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu)
	 */
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.splash, menu);
		return true;
	}
	
	/**
	 * this goes you to another activity
	 */
	private void goMainActivity(){
		startActivity(new Intent(this, MainMenu.class));
		this.finish();
	}
	
	/* (non-Javadoc)
	 * @see android.view.View.OnClickListener#onClick(android.view.View)
	 */
	@Override
	public void onClick(View v) {
		//there are not filters. It will be executed when touch the screen
		goMainActivity();
	}

	/* (non-Javadoc)
	 * @see android.view.animation.Animation.AnimationListener#onAnimationEnd
	 * (android.view.animation.Animation)
	 */
	@Override
	public void onAnimationEnd(Animation arg0) {
		goMainActivity();
	}

	/* (non-Javadoc)
	 * @see android.view.animation.Animation.AnimationListener#onAnimationRepeat
	 * (android.view.animation.Animation)
	 */
	@Override
	public void onAnimationRepeat(Animation arg0) {
		
	}

	/* (non-Javadoc)
	 * @see android.view.animation.Animation.AnimationListener#onAnimationStart
	 * (android.view.animation.Animation)
	 */
	@Override
	public void onAnimationStart(Animation arg0) {
		
	}

}
